<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="../js/prop-types.js"></script>
    <script type="text/babel">
        // 非受控组件，触发某个事件后去获取form表单内容
        class LoginModule extends React.Component {
            state = {
                username: '',
                password: ''
            }
            loginFn = (e) => {
                e.preventDefault()
                const { username, password } = this.state
                alert(`用户名：${username}，密码：${password}`)
            }
            /*
                函数柯里化 & 高阶函数
            */
            saveFormData = (type) => {
                return (e) => {
                    this.setState({
                        [type]: e.target.value
                    })
                }
            }
            render () {
                return (
                    <form>
                        用户名：<input type="text" onChange={this.saveFormData('username')} />
                        密码：<input type="password" onChange={this.saveFormData('password')} />
                        <button onClick={this.loginFn}>登录</button>
                    </form>
                )
            }
        }
        ReactDOM.render(<LoginModule />, document.getElementById('app'))
    </script>
</body>

</html>